import page from '../../databus/page';
import positionsAddTpl from '../../views/positions-add.art';
import {
  positionsAddModel
} from '../../models/positions';

//添加用户
export const addPosition = () => {

  //渲染模板 继users.art 渲染之后再渲染
  $('#position-list-box').after(positionsAddTpl());

  const _save = async () => {

    try {
      let result = await positionsAddModel();
      if (result.ret) {
        page.setCurrentPage(1);
        //获取用户列表数据
        //告知list页面要重新渲染
        $('body').trigger('addPosition');
      }
      //单击关闭模态框
      $('#positions-close').click();
    } catch (err) {
      console.log(err);
    }
  }

  //点击模态框保存，提交表单
  $('#positions-save').off('click').on('click', _save);
}